//
//  HWVoiceRoomGiftUserCell.swift
//  PlayWithProject
//
//  Created by 王昌健 on 2021/8/27.
//

import UIKit

class HWVoiceRoomGiftUserCell: UICollectionViewCell {
    var headImageView:UIImageView!
    var seatLabel:UILabel!
    var model:HWVoiceRoomSeatModel?{
        didSet {
            headImageView.sd_setImage(with: URL(string: model?.seatUser?.userFace ?? ""), completed: nil)
            if model?.seatIndex == 0 {
                seatLabel.text = "主持"
            }else if model?.seatIndex == 1 {
                seatLabel.text = "老板"
            }else {
                seatLabel.text = "\(model!.seatIndex - 1)号麦"
            }
            if model?.selected == true {
                headImageView.layer.borderColor = UIColor.colorWithHexString(hexString: "#FDDD00").cgColor
            }else{
                headImageView.layer.borderColor = UIColor.clear.cgColor
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
extension HWVoiceRoomGiftUserCell {
    private func initUI() -> Void {
        
        contentView.backgroundColor = .clear
        headImageView = UIImageView()
        headImageView.backgroundColor = .red
        headImageView.layer.cornerRadius = 15
        headImageView.layer.masksToBounds = true
        headImageView.layer.borderWidth = 1
        headImageView.layer.borderColor = UIColor.clear.cgColor
        contentView.addSubview(headImageView)
        
        seatLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 8)
        seatLabel.backgroundColor = .white
        seatLabel.layer.cornerRadius = 6
        seatLabel.layer.masksToBounds = true
        seatLabel.textAlignment = .center
        contentView.addSubview(seatLabel)
    }
    
    private func initFrame() -> Void {
        headImageView.snp.makeConstraints { make in
            make.left.right.top.equalTo(0)
            make.width.height.equalTo(30)
        }
        
        seatLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(headImageView.snp.bottom).offset(-4)
            make.height.equalTo(12)
            make.width.equalTo(25)
        }
    }
}
